import Vue from 'vue'

Vue.filter('time', (data, format) => {
  let date = new Date(data)
  data = format
  let Y,M,D,H,m,S
  if (format.includes('Y')) {
    Y = date.getFullYear()
    data = data.replace(/Y/g, Y)
  }
  
  if (format.includes('M')) {
    M = date.getMonth().toString().padStart(2, '0')
    data = data.replace(/M/g, M)
  }
  
  if (format.includes('D')) {
    D = date.getDay().toString().padStart(2, '0')
    data = data.replace(/D/g, D)
  }
  
  if (format.includes('H')) {
    H = date.getHours().toString().padStart(2, '0')
    data = data.replace(/H/g, H)
  }
  
  if (format.includes('m')) {
    m = date.getMinutes().toString().padStart(2, '0')
    data = data.replace(/m/g, m)
  }
  
  if (format.includes('S')) {
    S = date.getSeconds().toString().padStart(2, '0')
    data = data.replace(/S/g, S)
  }

  return data
})